#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int n, m, a[505][505], b[505][505], suma[505][505], sumb[505][505], dp[505][505];
int main()
{
    while (scanf("%d%d", &n, &m) != EOF)
    {
        if (n == 0 && m == 0)
            return 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                scanf("%d", &a[i][j]);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                scanf("%d", &b[i][j]);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
            {
                suma[i][j] = suma[i][j - 1] + a[i][j];
                sumb[i][j] = sumb[i - 1][j] + b[i][j];
            }
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                dp[i][j] = max(dp[i - 1][j] + suma[i][j], dp[i][j - 1] + sumb[i][j]);
        printf("%d\n", dp[n][m]);
    }
}